import os

with os.scandir('/var') as dirs:
    for entry in dirs:
        print(entry)

with os.scandir('/run') as dirs:
    for entry in dirs:
        if entry.is_dir():
            print("dir: ",entry.name)
        elif entry.is_file:
            print("file:", entry.name)
        elif entry.is_symlink():
            print("symlink:", entry.name)
        else:
            print("unkonw file", entry.name)
        
        print(entry.stat())
        """ entry.stat()
        os.stat_result(st_mode=33188, st_ino=745, st_dev=65, st_nlink=1, st_uid=0, st_gid=0, st_size=444, st_atime=1720088123, st_mtime=1720088123, st_ctime=1720088123)
        """

# 3.主动释放
dirs=os.scandir('/tmp')
for entry in dirs:
    print(entry)
dirs.close()
    
""" 

<DirEntry 'backups'>
<DirEntry 'lib'>
<DirEntry 'tmp'>
<DirEntry 'log'>
<DirEntry 'spool'>
<DirEntry 'opt'>
<DirEntry 'mail'>
<DirEntry 'lock'>
<DirEntry 'local'>
<DirEntry 'crash'>
<DirEntry 'run'>
<DirEntry 'snap'>
<DirEntry 'cache'>

"""


""" 
file: apport.socket
file: utmp
dir:  sudo
dir:  screen
dir:  sendsigs.omit.d
dir:  console-setup
dir:  log
dir:  udev
file: initctl
dir:  credentials

"""